Skip to content

feat(broker): scope enforcement inside withGovernance — exec-broker proper (Pillar 3 step 5) - #306

Merged
sandstream merged 1 commit into
mainfrom
claude/web-kit-status-sync-p6fg9a
Jul 10, 2026
Merged

sandstream merged 1 commit into
mainfrom
claude/web-kit-status-sync-p6fg9a

Conversation

@sandstream

Copy link
Copy Markdown
Owner

Description

The final build step of the Pillar 3 exec-broker (design: kit-research/docs/research/pillar3-exec-broker-5.0.md §3.4). The governance floor (withGovernance) now enforces the signed [scope]/RoE at exec time — including secret-scoped env — completing the advisory→enforced shift: every surface (PreToolUse gates #305, MCP/CLI governed ops here) now shares one scope core (#303) and one verified scope source (#304).

Type of Change

  • New feature (non-breaking change that adds functionality)

Related Issues

Changes Made

  • src/broker/needs.ts — ScopeNeeds { egress, fsWrites, secrets }: what a governed operation declares it is about to touch; checkScopeNeeds → denial reason | null:
    • no scope regime declared (none) → null — advisory floor unchanged, fully backward compatible;
    • scope declared but unsigned/tampered → declared needs denied (declaring a scope is the opt-in; only a verified one grants — same fail-closed rule as the gates);
    • verified → each need checked with the pure predicates. Secret-scoped env lands here: an op declaring a key outside [scope].secrets is denied before it runs.
  • src/governance-middleware.ts — additive optional OperationContext.scopeNeeds (frozen-contract safe) + enforcement step 2.5, checked before any approval prompt — a scope denial is not operator-overridable (widening the RoE means editing + re-signing the profile), so the operator is never prompted for an op that will be scope-denied anyway. Deny ⇒ auditDeny + throw; the operation never executes.
  • src/broker/needs.test.ts — 9 tests: unit (none / empty / unsigned / verified in+off-scope per dimension / tampered) + integration (withGovernance runs in-scope ops, never executes off-scope ops, fail-closes on an unsigned regime, byte-compatible for ops without scopeNeeds).

Testing

Test Coverage

  • Added new tests (9)
  • All tests pass (npm test) — full suite 2709 pass / 0 fail (2700 baseline + 9); the existing governance-middleware.test.ts suite is untouched and green

Manual Testing

  1. npx tsc --noEmit → clean; npx eslint src → 0 errors.
  2. npm run build && node scripts/test.mjs → 2709 pass, 0 fail.
  3. No public-surface change (no new verb; OperationContext is an internal type).

Breaking Changes

None / N/A — scopeNeeds is optional and additive; projects without a profile see no behavior change (proven by the backward-compat test).

Checklist

  • All new code has test coverage
  • All tests pass locally (npm test)
  • No new warnings or errors introduced
  • No hardcoded secrets or sensitive data
  • Code has been self-reviewed

Performance Impact

  • No performance impact — the scope check runs only when an operation declares scopeNeeds (one profile read + offline verify)

Reviewer Notes

Two placement decisions to sanity-check: (1) the scope step runs before approval prompts because a scope denial cannot be approved away — the RoE is a signed artifact, so prompting first would invite an approval that changes nothing; (2) the none vs unsigned asymmetry — no profile at all means no RoE regime (advisory floor unchanged), while a declared but unsigned scope is a taken opt-in that must be trustworthy to grant. This is deliberately the same rule the PreToolUse gates enforce, so the two enforcement points can't diverge. With this, the exec-broker's incremental plan (design §5, steps 1–5) is complete; what remains in Pillar 3 is adoption — wiring scopeNeeds declarations into individual MCP operations and an agent-config convenience for installing the gates.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DbF4MFePXWNCd4dxBQvqH2


Generated by Claude Code

…roper (Pillar 3 step 5)

Completes the exec-broker (design: pillar3-exec-broker-5.0.md §3.4): the governance floor now
ENFORCES the signed [scope]/RoE at exec time, including secret-scoped env.

- broker/needs.ts: ScopeNeeds { egress, fsWrites, secrets } — what a governed operation
  declares it is about to touch — and checkScopeNeeds(needs, cwd) → denial reason | null:
  * no scope regime declared (state none) → null — advisory floor unchanged, fully backward
    compatible (projects without a profile see no behavior change);
  * scope declared but unsigned/tampered → declared needs DENIED (declaring a scope is the
    opt-in; only a verified one grants — same fail-closed rule as the PreToolUse gates);
  * verified → each need checked with the pure predicates (hostInScope/pathInScope/
    secretInScope). Secret-scoped env lands here: an op that declares a key outside
    [scope].secrets is denied before it runs.
- governance-middleware.ts: additive optional OperationContext.scopeNeeds (frozen-contract
  safe) + enforcement step 2.5 — checked BEFORE any approval prompt, because a scope denial
  is not operator-overridable (widening the RoE means editing + re-signing the profile);
  deny → auditDeny + throw, the operation never executes.

9 tests (unit: none/empty/unsigned/verified-in+off-scope/tampered; integration: withGovernance
runs in-scope ops, never executes off-scope ops, fail-closes on unsigned regime, and is
byte-compatible for ops without scopeNeeds). Existing middleware suite untouched and green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbF4MFePXWNCd4dxBQvqH2
@github-actions

Copy link
Copy Markdown

✅ Docker image built successfully

  • CLI image: docker.io/sandstream/kit:test

@sandstream
sandstream merged commit 32fdcc0 into main Jul 10, 2026
18 checks passed
@sandstream
sandstream deleted the claude/web-kit-status-sync-p6fg9a branch July 10, 2026 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants